#!./common-test/bats/bin/bats
# -*-sh-*-

load ./common-test/test_helper_functions || exit 1
source ./common-test/functions || exit 1

if [ -s ./common-test/TEST_ENV ];then
   . ./common-test/TEST_ENV
else
    ERROR "TEST_ENV does not exist"
fi

CMD_TIMEOUT="5:00"
TEST_MAX_COMPUTES=1024
TEST_NUM_RANKS=2
TEST_NUM_THREADS=4
TEST_NUM_ITERS=10

app="App/PRK"
mode=MPISHM
rm=$RESOURCE_MANAGER
NUMITERS=$TEST_NUM_ITERS
NUMSUBPROCS=2
NODES=$((NUM_COMPUTES < TEST_MAX_COMPUTES ? NUM_COMPUTES : TEST_MAX_COMPUTES))
TASKS=$((NODES * TEST_NUM_RANKS))

@test "[$app] $mode/Stencil run under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    exe="$mode/Stencil/stencil"
    run_mpi_binary -t $CMD_TIMEOUT $exe "$NUMSUBPROCS $NUMITERS 1000" $NODES $TASKS
    assert_success
}

@test "[$app] $mode/Synch_p2p run under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    exe="$mode/Synch_p2p/p2p"
    run_mpi_binary -t $CMD_TIMEOUT $exe "$NUMITERS 1000 100" $NODES $TASKS
    assert_success
}

@test "[$app] $mode/Transpose run under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    exe="$mode/Transpose/transpose"
    run_mpi_binary -t $CMD_TIMEOUT $exe "$NUMSUBPROCS $NUMITERS 1000 64" $NODES $TASKS
    assert_success
}
